<?php
	namespace App\Middleware;
	use App\Model\UserModel;
	class RolrMiddleware extends BaseMiddleware{
		public function __invoke($request,$response,$next){
			//登录验证
//          if($_SESSION['username']==""){
//              return $response->withRedirect($this->container->router->pathFor('login'));
//          }
            $urlpath=$request->getUri()->getPath();
            $user1=$_SESSION['UserEmail'];
            $res= $this->CheckUser($user1,$urlpath);
            if($res==0){
                return $response->withRedirect($this->container->router->pathFor('notallow'));
            }else{
                $response=$next($request,$response);
            }
			return $response;
		}
		public function CheckUser($user1,$urlpath){
			$user=new UserModel();
			$sql="select controlleraction from user 
			inner join rolrpower
			on `user`.rolrid=rolrpower.rolrid
			inner join power
			on rolrpower.power=Power.id
			where email='".$user1."'and controlleraction='".$urlpath."'";
			$res=$user->query($sql);
			return $res;
		}
	}
